package drone.iqgc.controller ;

import java.util.Map ;

import org.springframework.stereotype.Controller ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.ResponseBody ;

import drone.basis.base.BaseController ;
import drone.basis.base.BaseResult ;
import drone.basis.dictionary.StateDict ;
import drone.basis.util.MapUtil ;
import drone.basis.util.StringUtil ;
import drone.iqgc.config.MapConfig ;

@Controller
@RequestMapping ( "map" )
public class MapController extends BaseController
{

	public MapController ( )
	{
		super ( "map" ) ;
	}

	@RequestMapping ( "location" )
	@ResponseBody
	public BaseResult < Object > reportLocation (
			@RequestBody ( required = false ) Map < String , String > paramMap
	) throws Exception
	{

		if ( StringUtil.isEmpty ( paramMap.get ( "lng" ) ) || StringUtil.isEmpty ( paramMap.get ( "lat" ) ) )
		{
			return new BaseResult.Builder < Object > ( ).codeInfo ( StateDict.NO.getCode ( ) ).messageInfo ( "没有相关位置信息" ).build ( ) ;
		}

		if ( new Double ( paramMap.get ( "lng" ) ) < 0 || new Double ( paramMap.get ( "lat" ) ) < 0 )
		{
			return new BaseResult.Builder < Object > ( ).codeInfo ( StateDict.NO.getCode ( ) ).messageInfo ( "没有相关位置信息" ).build ( ) ;
		}

		String addr = MapUtil.address ( MapConfig.GEO , "{'lon':" + paramMap.get ( "lng" ) + ",'lat':" + paramMap.get ( "lat" ) + ",'ver':1}" , "geocode" ) ;

		return new BaseResult.Builder < Object > ( ).codeInfo ( StateDict.YES.getCode ( ) ).messageInfo ( addr ).build ( ) ;
	}

}
